/**
 * Depends:
 * widget.search.string.js
 */
$.fn.galleryWidget = function(options){
	var $this = this;
	options = options || {};
    var mainPhotoContainerSelector = options.mainPhotoContainerSelector 	|| '.main-photo';
	var mainPhotoSelector 	= options.mainPhotoSelector 	|| 'img';
	var thumbsSelector		= options.thumbsSelector 		|| '.small-photo';

	/**
	 * 
	 */
	$this._init = function(){
        $this.mainPhotoContainer = $(this).find(mainPhotoContainerSelector);
		$this.mainPhoto = $this.mainPhotoContainer.find(mainPhotoSelector);
		$this.thumbs  =   $(this).find(thumbsSelector);
	};
	
	/**
	 * 
	 */
	$this._bindEvents = function(){
        $('a.map-info').colorbox({
            photo: true
        });
		/* ----------------------------------------- */
		$this.thumbs.each(function(){
			$(this).click(function(){
				$this.mainPhoto.attr('src', $(this).closest('a').attr('rev'));
                $this.mainPhotoContainer.attr('href', $(this).closest('a').attr('href'));
				return false;
			});
		});
		/* ----------------------------------------- */
		$this.mainPhoto.click(function(){
            $('a.other-photo').colorbox({
                photo:true,
                open:true,
                current: "фото {current} из {total}",
                next : "следующее",
                previous : "предыдущее"
            });
            return false;
		});
		/* ----------------------------------------- */
	};
	/**
	 * Implementation
	 */
	$this._init();
	$this._bindEvents();
	
	return $(this);
};